<template>
  <div class="home-box">
    <el-container class="home-container">
      <!-- 头部区域 -->
      <el-header>
        <div>
          <img src="../assets/logo.png"/>
          <span style="font-size: 20px;color: white">汽车后台管理系统</span>
        </div>
        <el-dropdown @command="handleCommand">
          <el-avatar :src="this.imgurl"></el-avatar>
          <span style="font-weight: bolder;color: white" >{{this.userName}}</span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="1" @click.native="person()">个人中心</el-dropdown-item>
            <el-dropdown-item command="2" @click.native="editPassword()">修改密码</el-dropdown-item>
            <el-dropdown-item  @click.native="out()">退出登录</el-dropdown-item>

          </el-dropdown-menu>
        </el-dropdown>

      </el-header>
      <!-- 页面主体区域 -->
      <el-container>
        <!-- 侧边栏 -->
        <!-- 侧边栏,宽度根据是否折叠进行设置 -->
        <el-aside :width="isCollapse ? '200px':'200px'">
          <!-- 伸缩侧边栏按钮 -->
          <div class="toggle-button" @click="toggleCollapse">|||</div>
          <!-- 侧边栏菜单 -->
          <el-menu
                  background-color="#333744"
                  text-color="#fff"
                  router
                  :collapse="isCollapse"
                  active-text-color="#ffd04b">
            <NavMenu :menuData="menuList"></NavMenu>
          </el-menu>
        </el-aside>
        <!-- 主体结构 -->
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
  import NavMenu from "../components/duojicaidan.vue"
    export default {
        name: "Home",
        components:{
            NavMenu:NavMenu
        },
        data(){
            return {
                isCollapse:true,
                menuList:[],
                userName:"",
                imgurl:''
            }

        },
        created() {
            //根据token获取用户的信息

            //初始化菜单

        },
        methods: {
            person(){
                this.$router.push("PersonCenter");
            },
            editPassword(){
                this.$router.push("EditPassword");
            },
            out(){
                sessionStorage.removeItem("token");
                this.$router.push("login");
            },
            queryMenuByuserid(){
                var that = this
                this.$http.get("system/menu/queryMenubyUserid").then(r=>{
                    console.log(r.data.result.leftMenus)
                    that.menuList=r.data.result.leftMenus
                   sessionStorage.setItem("username",r.data.result.username)
                    that.userName=r.data.result.username;
                    that.imgurl=r.data.result.img;
                    console.log(that.imgurl)
                    sessionStorage.setItem("id",r.data.result.id)
            })
            },

            handleCommand(command){
                this.$message('click on item ' + command);
            },
            toggleCollapse(){
                this.isCollapse=!this.isCollapse;
            }
        },
        mounted(){
            this.queryMenuByuserid();
        }
    }
</script>
<style scoped lang="less">
  .home-box{
    height: 100%;
  }
  .home-container {
    height: 100%;
  }
  .el-header{
    background-color:#3C8DBC;
    display: flex;
    justify-content: space-between;
    padding-left: 0px;
    align-items: center;
    color: white;
    font-size: 20px;
    > div{
      display: flex;
      align-items: center;
      span{
        margin-left: 15px;
      }
    }
  }
  .el-aside{
    background-color:#333744;
    height: 100%;
    .el-menu{
      border-right: none;
    }
  }
  .el-main{
    background-color:#eaedf1;
  }
  .toggle-button{
    display: flex;
    justify-content: center;
    color: white;
  }
</style>